using System.Collections;
using System.Collections.Generic;
using System.Xml;
using UnityEngine;

public class SaveXml : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        string path=Application.persistentDataPath+"/TestXml.xml";
        Debug.Log(Application.persistentDataPath);
        XmlDocument xmldocument = new XmlDocument();
        XmlDeclaration xmlDeclaration = xmldocument.CreateXmlDeclaration("1.0", "UTF-8", "");
        XmlElement Root=xmldocument.CreateElement("Root");
        xmldocument.AppendChild(Root);
        XmlElement name=xmldocument.CreateElement("Name");
        name.InnerText = "abab";
        Root.AppendChild(name);
        XmlElement Item=xmldocument.CreateElement("Item");
        XmlElement id =xmldocument.CreateElement("id");
        id.InnerText = "10";
        XmlElement num=xmldocument.CreateElement ("num");
        num.InnerText = "1";
        Item.AppendChild(id);
        Item.AppendChild(num);
        Root.AppendChild(Item);
        XmlElement ListItem = xmldocument.CreateElement("XmlItem");
        for(int i = 0; i < 10; i++)
        {
            XmlElement childnode = xmldocument.CreateElement("int");
            childnode.InnerText = i.ToString();
            ListItem.AppendChild(childnode);
            XmlElement item=xmldocument.CreateElement("item");
            item.SetAttribute("id", i.ToString());
            item.SetAttribute ("num", (10*i).ToString());
            ListItem.AppendChild(item);
        }
        Root.AppendChild(ListItem);

       
        xmldocument.Save(path);
        XmlDocument xml = new XmlDocument();
        xml.Load(path);
        XmlNode Root2 = xml.SelectSingleNode("Root");
        Root2.RemoveChild(xml.SelectSingleNode("Root/Name"));
        xml.Save(path);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
